package com.ssm.xm.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class Cut {
    //配置切入点
    @Pointcut("execution(* com.ssm.xm.service.*.*(..))")
    public void cut() {

    }
    @Around("cut()")
    public Object around(ProceedingJoinPoint joinPoint){
        System.out.println("前置通知");
        Object o = null;
        try {
            long l = System.currentTimeMillis();
            o = joinPoint.proceed();
            String className = joinPoint.getTarget().getClass().getName();
            String methodName = joinPoint.getSignature().getName();
            String path = Arrays.toString(joinPoint.getArgs());
            System.out.println("被增强的类："+className);
            System.out.println("被增强的方法："+methodName);
            System.out.println("被增强的方法参数："+path);
            System.out.println("总耗时"+(System.currentTimeMillis()-l)+"毫秒");
        } catch (Throwable e) {
            System.out.println("异常通知");
            e.printStackTrace();
        }finally {
            System.out.println("最终通知");
        }
        return o;
    }
}
